using ASP;
using HoWave.Common;
using HoWave.Web.Shop.Member;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_ShopProductSold : Member, IRequiresSessionState
{
	private string wherestr = "";
	private ArrayList al = new ArrayList();
	private IDbDataParameter[] param = null;
	protected TextBox TxtBeginDate;
	protected TextBox TxtEndDate;
	protected TextBox TxtOrderName;
	protected DropDownList RadProductType;
	protected Button search_btn;
	protected HtmlTable tb1;
	protected GridView GridView1;
	protected HtmlGenericControl product_history;
	protected GridView GridView2;
	protected TextBox ComentBox;
	protected HtmlGenericControl divCommnet;
	protected Button ReturnBut;
	protected Panel Panel1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (base.Request["ProductID"] != null)
			{
				string s = base.Request["ProductID"].ToString().Substring(1, base.Request["ProductID"].ToString().Length - 2);
				this.BindViewComment(int.Parse(s));
				this.product_history.Visible = false;
				this.tb1.Visible = false;
				this.Panel1.Visible = true;
			}
			else
			{
				this.Panel1.Visible = false;
				this.BindList();
			}
		}
		this.TxtBeginDate.Attributes.Add("onclick", "SelectDate(" + this.TxtBeginDate.UniqueID + ",'yyyy-MM-dd');");
		this.TxtEndDate.Attributes.Add("onclick", "SelectDate(" + this.TxtEndDate.UniqueID + ",'yyyy-MM-dd');");
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.GridView1_PageIndexChanging);
	}
	public string CountNum(string StrProductID, object productid)
	{
		int num = int.Parse(StrProductID);
		string sql = string.Concat(new object[]
		{
			"select COUNT(*) from HLMall_Credit where OrderFormNum in (select OrderFormNum from HLShop_OrderItem where ProductID=",
			num,
			") and ByValuerID=",
			base.user.UserID
		});
		int num2 = this.conn.ExecuteCount(sql);
		string result;
		if (num2 > 0)
		{
			result = string.Concat(new object[]
			{
				"<a href=\"Shop_ProductSold.aspx?ProductID='",
				productid,
				"'&tag=Views\">查看评价(<span style=\"color: Red; font-weight: bold\">",
				num2,
				"</span>)</a>"
			});
		}
		else
		{
			result = "<a>查看评价(<span style=\"color: Red; font-weight: bold\">" + num2 + "</span>)</a>";
		}
		return result;
	}
	protected void BindList()
	{
		this.QuestString();
		string text = "Select * From [HLShop_Product] Where ProductID in(Select I.ProductID From [HLShop_OrderItem] I Inner Join [HLShop_Order] O On O.OrderFormID=I.OrderFormID Where O.SalerID=" + base.user.UserID + ") ";
		text += this.wherestr;
		text += " ";
		if (this.al.Count > 0)
		{
			this.param = new IDbDataParameter[this.al.Count];
			this.al.CopyTo(this.param, 0);
		}
		if (this.param == null)
		{
			this.GridView1.DataSource = this.conn.GetDataTable(text);
		}
		else
		{
			this.GridView1.DataSource = this.conn.GetDataTable(text, this.param);
		}
		this.GridView1.DataBind();
		for (int i = 0; i < this.GridView1.Rows.Count; i++)
		{
			GridViewRow gridViewRow = this.GridView1.Rows[i];
			HiddenField hiddenField = (HiddenField)gridViewRow.FindControl("hfProductType");
			HiddenField hiddenField2 = (HiddenField)gridViewRow.FindControl("hfProductName");
			HyperLink hyperLink = (HyperLink)gridViewRow.FindControl("view");
			if (hiddenField != null && hiddenField2 != null)
			{
				string a = hiddenField.Value.Trim();
				if (a == "3")
				{
					if (hyperLink != null)
					{
						hyperLink.NavigateUrl = "Shop_TeamBuy.aspx?productname=" + hiddenField2.Value;
					}
				}
				else
				{
					if (a == "2")
					{
						if (hyperLink != null)
						{
							hyperLink.NavigateUrl = "Shop_SalerAuction.aspx";
						}
					}
				}
			}
		}
	}
	protected void QuestString()
	{
		this.wherestr = "and SalerID=" + base.user.UserID + " ";
		string text = this.TxtOrderName.Text.Trim();
		if (text != string.Empty)
		{
			this.wherestr += "and ProductName like '%' + @OrderName + '%' ";
			this.al.Add(this.conn.CreateParameter("@OrderName", DbType.String, text.Trim()));
		}
		string text2 = this.TxtBeginDate.Text;
		if (text2 != string.Empty)
		{
			if (!Text.IsDate(text2))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			this.wherestr += " and BeginDate > @BeginDate ";
			this.al.Add(this.conn.CreateParameter("@BeginDate", DbType.DateTime, Convert.ToDateTime(text2)));
		}
		string text3 = this.TxtEndDate.Text;
		if (text3 != string.Empty)
		{
			if (!Text.IsDate(text3))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			if (text2 != string.Empty)
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			this.wherestr += " and EndDate < @EndDate ";
			this.al.Add(this.conn.CreateParameter("@EndDate", DbType.DateTime, Convert.ToDateTime(text3)));
		}
		string selectedValue = this.RadProductType.SelectedValue;
		if (selectedValue != string.Empty && selectedValue != "0")
		{
			object obj = this.wherestr;
			this.wherestr = string.Concat(new object[]
			{
				obj,
				"and ProductType=",
				int.Parse(selectedValue),
				" "
			});
		}
	}
	protected void Search_OnClick(object sender, EventArgs e)
	{
		this.BindList();
	}
	private void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindList();
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			if (gridViewRow.RowType == DataControlRowType.DataRow)
			{
				gridViewRow.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
				gridViewRow.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
			}
		}
	}
	public void BindViewComment(int ProID)
	{
		string sql = string.Concat(new object[]
		{
			"select * from HLMall_Credit where OrderFormNum in (select OrderFormNum from HLShop_OrderItem where ProductID=",
			ProID,
			") and ByValuerID=",
			base.user.UserID
		});
		DataSet dataSet = this.conn.GetDataSet(sql);
		this.GridView2.DataSource = dataSet;
		this.GridView2.DataBind();
	}
	public string Levelrate(object RateScore)
	{
		string result = "<img src='../Images/CreditImage/rate-ok.gif'/>好评";
		if (RateScore != null)
		{
			string text = RateScore.ToString();
			if (text != null)
			{
				if (!(text == "0"))
				{
					if (text == "-1")
					{
						result = "<img src='../Images/CreditImage/rate-bad.gif'/>差评";
					}
				}
				else
				{
					result = "<img src='../Images/CreditImage/rate-normal.gif'/>中评";
				}
			}
		}
		return result;
	}
	public DataSet GetComment(int CommentID)
	{
		return this.conn.GetDataSet("select * from HLMall_Credit where CreditID=" + CommentID);
	}
	protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
	{
		if (e.CommandName == "LBut")
		{
			GridViewRow gridViewRow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
			int rowIndex = gridViewRow.RowIndex;
			int commentID = int.Parse(this.GridView2.Rows[rowIndex].Cells[0].Text);
			DataSet comment = this.GetComment(commentID);
			if (comment.Tables[0].Rows.Count > 0)
			{
				this.ComentBox.Text = comment.Tables[0].Rows[0]["Comment"].ToString();
			}
			this.divCommnet.Visible = true;
		}
	}
	protected void ReturnBut_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("Shop_ProductSold.aspx");
	}
}
